home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xroach-v12 / xroach.patch1 < prev   
Text File  |  1995-06-20  |  11KB  |  461 lines

  1. *** patchlevel.h    Tue Apr 02 11:59:19 1991
  2. --- ../xroach/patchlevel.h    Tue Apr 02 11:57:25 1991
  3. ***************
  4. *** 1 ****
  5. ! #define PATCHLEVEL 0
  6. --- 1,4 ----
  7. ! /* @(#)patchlevel.h    1.2 4/2/91 11:57:18 */
  8. ! #define PATCHLEVEL 1
  9. *** roachmap.h    Tue Apr 02 11:59:19 1991
  10. --- ../xroach/roachmap.h    Tue Apr 02 11:55:42 1991
  11. ***************
  12. *** 1,3 ****
  13. --- 1,6 ----
  14. + /* @(#)roachmap.h    1.3 4/2/91 11:55:35 */
  15.   #include "roach000.xbm"
  16.   #include "roach015.xbm"
  17.   #include "roach030.xbm"
  18. ***************
  19. *** 22,27 ****
  20. --- 25,32 ----
  21.   #include "roach315.xbm"
  22.   #include "roach330.xbm"
  23.   #include "roach345.xbm"
  24. + #include "squish.xbm"
  25.   
  26.   #define ROACH_HEADINGS    24    /* number of orientations */
  27.   #define ROACH_ANGLE    15    /* angle between orientations */
  28. *** xroach.c    Tue Apr 02 11:59:18 1991
  29. --- ../xroach/xroach.c    Tue Apr 02 11:53:42 1991
  30. ***************
  31. *** 12,21 ****
  32. --- 12,31 ----
  33.         cc -o xroach roach.c -lX11 [-lsocketorwhatever] [-lm] [-l...]
  34.   
  35.       Dedicated to Greg McFarlane.   (gregm@otc.otca.oz.au)
  36. +     
  37. +     Squish option contributed by Rick Petkiewizc (rick@locus.com)
  38. +     
  39. +     Virtual root code adapted from patch sent by Colin Rafferty who
  40. +     borrowed it from Tom LaStrange.  Several other folks sent similar
  41. +     fixes.
  42.   */
  43. + /* @(#)xroach.c    1.5 4/2/91 11:53:31 */
  44.   #include <X11/Xlib.h>
  45.   #include <X11/Xutil.h>
  46.   #include <X11/Xos.h>
  47. + #include <X11/Xatom.h>
  48.   
  49.   #include <stdio.h>
  50.   #include <math.h>
  51. ***************
  52. *** 49,54 ****
  53. --- 59,65 ----
  54.   unsigned int display_width, display_height;
  55.   int center_x, center_y;
  56.   GC gc;
  57. + GC gutsGC;
  58.   char *display_name = NULL;
  59.   Pixel black, white;
  60.   
  61. ***************
  62. *** 55,60 ****
  63. --- 66,74 ----
  64.   int done = 0;
  65.   int eventBlock = 0;
  66.   int errorVal = 0;
  67. + Bool squishRoach = False;
  68. + Pixmap squishMap;
  69. + Bool squishWinUp = False;
  70.   
  71.   typedef struct Roach {
  72.       RoachMap *rp;
  73. ***************
  74. *** 84,89 ****
  75. --- 98,104 ----
  76.   int CalcRootVisible();
  77.   int MarkHiddenRoaches();
  78.   Pixel AllocNamedColor();
  79. + Window FindRootWindow();
  80.   
  81.   void
  82.   main(ac, av)
  83. ***************
  84. *** 98,105 ****
  85. --- 113,123 ----
  86.       float angle;
  87.       XEvent ev;
  88.       char *roachColor = "black";
  89. +     char *gutsColor = NULL;
  90.       int nVis;
  91.       int needCalc;
  92. +     Window squishWin;
  93. +     XSetWindowAttributes xswa;
  94.       
  95.       /*
  96.          Process command line options.
  97. ***************
  98. *** 118,123 ****
  99. --- 136,147 ----
  100.       else if (strcmp(arg, "-roaches") == 0) {
  101.           maxRoaches = strtol(av[++ax], (char **)NULL, 0);
  102.       }
  103. +     else if (strcmp(arg, "-squish") == 0) {
  104. +         squishRoach = True;
  105. +     }
  106. +     else if (strcmp(arg, "-rgc") == 0) {
  107. +         gutsColor = av[++ax];
  108. +     }
  109.       else {
  110.           Usage();
  111.       }
  112. ***************
  113. *** 142,148 ****
  114.       }
  115.   
  116.       screen = DefaultScreen(display);
  117. !     rootWin = RootWindow(display, screen);
  118.       black = BlackPixel(display, screen);
  119.       white = WhitePixel(display, screen);
  120.   
  121. --- 166,172 ----
  122.       }
  123.   
  124.       screen = DefaultScreen(display);
  125. !     rootWin = FindRootWindow();
  126.       black = BlackPixel(display, screen);
  127.       white = WhitePixel(display, screen);
  128.   
  129. ***************
  130. *** 164,179 ****
  131. --- 188,229 ----
  132.       rp->cosine = cos(angle);
  133.       }
  134.   
  135. +     /*
  136. +       Create the squished pixmap
  137. +     */
  138. +     if (squishRoach) {
  139. +         squishMap = XCreateBitmapFromData(display, rootWin,
  140. +         squish_bits, squish_width, squish_height);
  141. +     }
  142.       roaches = (Roach *)malloc(sizeof(Roach) * maxRoaches);
  143.   
  144.       gc = XCreateGC(display, rootWin, 0L, &xgcv);
  145.       XSetForeground(display, gc, AllocNamedColor(roachColor, black));
  146.       XSetFillStyle(display, gc, FillStippled);
  147. +     if (squishRoach && gutsColor != NULL) {
  148. +         gutsGC = XCreateGC(display, rootWin, 0L, &xgcv);
  149. +         XSetForeground(display, gutsGC, AllocNamedColor(gutsColor, black));
  150. +         XSetFillStyle(display, gutsGC, FillStippled);
  151. +     }
  152. +     else
  153. +     gutsGC = gc;
  154.       
  155.       while (curRoaches < maxRoaches)
  156.       AddRoach();
  157.       
  158.       XSelectInput(display, rootWin, ExposureMask | SubstructureNotifyMask);
  159. +     if (squishRoach) {
  160. +     xswa.event_mask = ButtonPressMask;
  161. +     xswa.override_redirect = True;
  162. +     squishWin = XCreateWindow(display, rootWin, 0, 0,
  163. +             display_width, display_height, 0,
  164. +             CopyFromParent, InputOnly, CopyFromParent,
  165. +             CWOverrideRedirect | CWEventMask, &xswa);
  166. +     XLowerWindow(display, squishWin);
  167. +     }
  168.       
  169.       needCalc = 1;
  170.       while (!done) {
  171. ***************
  172. *** 184,195 ****
  173.           if (needCalc) {
  174.           needCalc = CalcRootVisible();
  175.           }
  176. !         nVis = MarkHiddenRoaches();
  177.           if (nVis) {
  178.           ev.type = SCAMPER_EVENT;
  179.           }
  180.           else {
  181. !         DrawRoaches();
  182.           eventBlock = 1;
  183.           XNextEvent(display, &ev);
  184.           eventBlock = 0;
  185. --- 234,257 ----
  186.           if (needCalc) {
  187.           needCalc = CalcRootVisible();
  188.           }
  189. !         if (needCalc)
  190. !         nVis = 0;
  191. !         else
  192. !             nVis = MarkHiddenRoaches();
  193.           if (nVis) {
  194.           ev.type = SCAMPER_EVENT;
  195. +         if (!squishWinUp && squishRoach) {
  196. +             XMapWindow(display, squishWin);
  197. +             squishWinUp = True;
  198. +         }
  199.           }
  200.           else {
  201. !         if (squishWinUp && squishRoach) {
  202. !             XUnmapWindow(display, squishWin);
  203. !             squishWinUp = False;
  204. !         }
  205. !         if (needCalc == 0)
  206. !             DrawRoaches();
  207.           eventBlock = 1;
  208.           XNextEvent(display, &ev);
  209.           eventBlock = 0;
  210. ***************
  211. *** 207,218 ****
  212.           XSync(display, False);
  213.           break;
  214.           
  215. -         case Expose:
  216. -         case MapNotify:
  217.           case UnmapNotify:
  218.           case ConfigureNotify:
  219.           needCalc = 1;
  220.           break;
  221.           
  222.       }
  223.       }
  224. --- 269,288 ----
  225.           XSync(display, False);
  226.           break;
  227.           
  228.           case UnmapNotify:
  229. +         if (ev.xunmap.window != squishWin)
  230. +             needCalc = 1;
  231. +         break;
  232. +         case MapNotify:
  233. +         case Expose:
  234.           case ConfigureNotify:
  235.           needCalc = 1;
  236.           break;
  237. +     
  238. +         case ButtonPress:
  239. +         checkSquish(&ev);
  240. +         break;
  241.           
  242.       }
  243.       }
  244. ***************
  245. *** 233,238 ****
  246. --- 303,310 ----
  247.       USEPRT("       -rc      roachcolor\n");
  248.       USEPRT("       -roaches numroaches\n");
  249.       USEPRT("       -speed   roachspeed\n");
  250. +     USEPRT("       -squish\n");
  251. +     USEPRT("       -rgc     roachgutscolor\n");
  252.       
  253.       exit(1);
  254.   }
  255. ***************
  256. *** 256,261 ****
  257. --- 328,391 ----
  258.   }
  259.   
  260.   /*
  261. +    Find the root or virtual root window.
  262. + */
  263. + Window
  264. + FindRootWindow()
  265. + {
  266. +     Window rootWin;
  267. +     Window realRoot;
  268. +     Atom swmVroot;
  269. +     Window rootReturn, parentReturn, *children;
  270. +     unsigned int numChildren;
  271. +     int cx;
  272. +     Atom actualType;
  273. +     Atom actualFormat;
  274. +     unsigned long nItems;
  275. +     unsigned long bytesAfter;
  276. +     Window *newRoot;
  277. +     
  278. +     /*
  279. +        Get real root window.
  280. +     */
  281. +     realRoot = rootWin = RootWindow(display, screen);
  282. +     
  283. +     /*
  284. +        Get atom for virtual root property.  If the atom doesn't
  285. +        exist, we can assume the corresponding property does not
  286. +        exist. 
  287. +     */
  288. +     swmVroot = XInternAtom(display, "__SWM_VROOT", True);
  289. +     
  290. +     if (swmVroot == None)
  291. +     return rootWin;
  292. +     
  293. +     /*
  294. +        Run children of root, looking for a virtual root.
  295. +     */
  296. +     XQueryTree(display, rootWin, &rootReturn, &parentReturn, 
  297. +             &children, &numChildren);
  298. +     for (cx=0; cx<numChildren; cx++) {
  299. +     newRoot = NULL;
  300. +     nItems = 0;
  301. +     if (XGetWindowProperty(display, children[cx], swmVroot, 0L, 1L, False,
  302. +         XA_WINDOW, &actualType, &actualFormat, &nItems,
  303. +         &bytesAfter, &newRoot) == Success && actualFormat != None) {
  304. +         if (nItems >= 1) {
  305. +             rootWin = *newRoot;
  306. +         }
  307. +         if (newRoot) {
  308. +             XFree(newRoot);
  309. +         }
  310. +     }
  311. +     if (rootWin != realRoot) break;
  312. +     }
  313. +     XFree(children);
  314. +     
  315. +     return rootWin;
  316. + }
  317. + /*
  318.      Generate random integer between 0 and maxVal-1.
  319.   */
  320.   int
  321. ***************
  322. *** 404,410 ****
  323.       for (rx=0; rx<curRoaches; rx++) {
  324.       roach = &roaches[rx];
  325.       
  326. !     if (roach->intX >= 0) {
  327.           XClearArea(display, rootWin, roach->intX, roach->intY,
  328.           roach->rp->width, roach->rp->height, False);
  329.       }
  330. --- 534,540 ----
  331.       for (rx=0; rx<curRoaches; rx++) {
  332.       roach = &roaches[rx];
  333.       
  334. !     if (roach->intX >= 0 && roach->rp != NULL) {
  335.           XClearArea(display, rootWin, roach->intX, roach->intY,
  336.           roach->rp->width, roach->rp->height, False);
  337.       }
  338. ***************
  339. *** 505,515 ****
  340.       */
  341.       covered = XCreateRegion();
  342.       for (wx=0; wx<nChildren; wx++) {
  343. !     if (XEventsQueued(display, QueuedAlready)) return 1;
  344.       errorVal = 0;
  345.       XGetWindowAttributes(display, children[wx], &wa);
  346.       if (errorVal) continue;
  347. !     if (wa.map_state == IsViewable) {
  348.           XGetGeometry(display, children[wx], &dummy, &winX, &winY,
  349.           &winWidth, &winHeight, &borderWidth, &depth);
  350.           if (errorVal) continue;
  351. --- 635,648 ----
  352.       */
  353.       covered = XCreateRegion();
  354.       for (wx=0; wx<nChildren; wx++) {
  355. !     if (XEventsQueued(display, QueuedAlready)) {
  356. !         XDestroyRegion(covered);
  357. !         return 1;
  358. !     }
  359.       errorVal = 0;
  360.       XGetWindowAttributes(display, children[wx], &wa);
  361.       if (errorVal) continue;
  362. !     if (wa.class == InputOutput && wa.map_state == IsViewable) {
  363.           XGetGeometry(display, children[wx], &dummy, &winX, &winY,
  364.           &winWidth, &winHeight, &borderWidth, &depth);
  365.           if (errorVal) continue;
  366. ***************
  367. *** 606,609 ****
  368. --- 739,783 ----
  369.       }
  370.   
  371.       return pix;
  372. + }
  373. + /*
  374. +  *    squishCheck - Check to see if we have to squish any roaches.
  375. +  */
  376. + checkSquish(buttonEvent)
  377. + XButtonEvent *buttonEvent;
  378. + {
  379. +     int x, y;
  380. +     int i;
  381. +     int rx;
  382. +     Roach *r;
  383. + /* */
  384. +     x = buttonEvent->x;
  385. +     y = buttonEvent->y;
  386. +     for (rx=0; rx<curRoaches; rx++) {
  387. +     r = &roaches[rx];
  388. +     if (r->rp == NULL) continue;
  389. +     if (x > r->intX &&
  390. +         x < (r->intX + r->rp->width) &&
  391. +         y > r->intY &&
  392. +         y < (r->intY + r->rp->height)) {
  393. +         XSetStipple(display, gutsGC, squishMap);
  394. +         XSetTSOrigin(display, gutsGC, r->intX, r->intY);
  395. +         XFillRectangle(display, rootWin, gutsGC,
  396. +         r->intX, r->intY, squish_width, squish_height);
  397. +         /*
  398. +          * Delete the roach
  399. +          */
  400. +         for (i = rx; i < curRoaches - 1; i++)
  401. +             roaches[i] = roaches[i + 1];
  402. +     
  403. +         curRoaches--;
  404. +         rx--;
  405. +     }
  406. +     }
  407. +     return;
  408.   }
  409. *** xroach.man    Tue Apr 02 12:26:11 1991
  410. --- ../xroach/xroach.man    Tue Apr 02 12:46:43 1991
  411. ***************
  412. *** 9,15 ****
  413.   displays disgusting cockroaches on your root window. These creapy crawlies
  414.   scamper
  415.   around until they find a window to hide under. Whenever you move or iconify
  416. ! a window, the exposed beetles again scamper for cover.
  417.   .SH OPTIONS
  418.   .TP 8
  419.   .B \-display \fIdisplay_name\fB
  420. --- 9,15 ----
  421.   displays disgusting cockroaches on your root window. These creapy crawlies
  422.   scamper
  423.   around until they find a window to hide under. Whenever you move or iconify
  424. ! a window, the exposed orthopteras again scamper for cover.
  425.   .SH OPTIONS
  426.   .TP 8
  427.   .B \-display \fIdisplay_name\fB
  428. ***************
  429. *** 26,31 ****
  430. --- 26,38 ----
  431.   .TP 8
  432.   .B \-roaches \fInum_roaches\fB
  433.   This is the number of the little critters. Default is 10.
  434. + .TP 8
  435. + .B \-squish
  436. + Enables roach squishing.  Point and shoot with any mouse button.
  437. + .TP 8
  438. + .B \-rgc \fIroach_gut_color\fB
  439. + Sets color of the guts that spill out of squished roaches.  We recommend
  440. + yellowgreen.
  441.   .SH BUGS
  442.   As given by the -roaches option. Default is 10.
  443.   .SH COPYRIGHT
  444.